package com.sibu.yx.promotion.persistence.config;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

import com.sibu.yx.promotion.persistence.util.SpringUtil;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author yuwenbo
 * @create 2019-04-08 16:21
 * 配置
 **/
@Data
@Slf4j
@Configuration
public class AppConfig implements InitializingBean {

    private static AppConfig appConfig = null;

    public static AppConfig getInstance() {
        if (appConfig == null) {
            synchronized (AppConfig.class) {
                appConfig = SpringUtil.getBean("appConfig");
            }
        }
        return appConfig;
    }


    @Value("${application.environment.name}")
    private String environmentName;


    @Override
    public void afterPropertiesSet() {
        Assert.notNull(environmentName, "environmentName is not set");
    }

    public boolean isProdEnv() {
        return "prod".equalsIgnoreCase(getEnvironmentName());
    }
}
